{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、数据抓取"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （1）调用模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import re"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （2）数据爬取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from bs4 import BeautifulSoup\n",
    "from time import sleep\n",
    "from csv import DictWriter\n",
    "##模拟headers登录\n",
    "base_url = r'https://movie.douban.com/top250'\n",
    "header = {\n",
    "        \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\"}\n",
    "#init_page = requests.get(url, headers=header).content\n",
    "records = []\n",
    "#for循环遍历链接\n",
    "for start in [x*25 for x in range(10)]:\n",
    "    #Every single page\n",
    "    url = base_url+f'?start={start}&filter='\n",
    "    response = requests.get(url,headers=header).text\n",
    "    soup = BeautifulSoup(response,'html.parser')\n",
    "    movies = soup.find(class_='grid_view').find_all('li')\n",
    "    rank=1+start\n",
    "    for movie in movies:\n",
    "        #Every single movie on the page\n",
    "        movie_link = movie.find(class_='info').find(class_='hd').find('a')['href']\n",
    "        movie_dict = {'rank':rank, 'link':movie_link}\n",
    "        records.append(movie_dict)\n",
    "        rank += 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Scarpping rank 1 of 250\n",
      "Scarpping rank 2 of 250\n",
      "Scarpping rank 3 of 250\n",
      "Scarpping rank 4 of 250\n",
      "Scarpping rank 5 of 250\n",
      "Scarpping rank 6 of 250\n",
      "Scarpping rank 7 of 250\n",
      "Scarpping rank 8 of 250\n",
      "Scarpping rank 9 of 250\n",
      "Scarpping rank 10 of 250\n",
      "Scarpping rank 11 of 250\n",
      "Scarpping rank 12 of 250\n",
      "Scarpping rank 13 of 250\n",
      "Scarpping rank 14 of 250\n",
      "Scarpping rank 15 of 250\n",
      "Scarpping rank 16 of 250\n",
      "Scarpping rank 17 of 250\n",
      "Scarpping rank 18 of 250\n",
      "Scarpping rank 19 of 250\n",
      "Scarpping rank 20 of 250\n",
      "Scarpping rank 21 of 250\n",
      "Scarpping rank 22 of 250\n",
      "Scarpping rank 23 of 250\n",
      "Scarpping rank 24 of 250\n",
      "Scarpping rank 25 of 250\n",
      "Scarpping rank 26 of 250\n",
      "Scarpping rank 27 of 250\n",
      "Scarpping rank 28 of 250\n",
      "Scarpping rank 29 of 250\n",
      "Scarpping rank 30 of 250\n",
      "Scarpping rank 31 of 250\n",
      "Scarpping rank 32 of 250\n",
      "Scarpping rank 33 of 250\n",
      "Scarpping rank 34 of 250\n",
      "Scarpping rank 35 of 250\n",
      "Scarpping rank 36 of 250\n",
      "Scarpping rank 37 of 250\n",
      "Scarpping rank 38 of 250\n",
      "Scarpping rank 39 of 250\n",
      "Scarpping rank 40 of 250\n",
      "Scarpping rank 41 of 250\n",
      "Scarpping rank 42 of 250\n",
      "Scarpping rank 43 of 250\n",
      "Scarpping rank 44 of 250\n",
      "Scarpping rank 45 of 250\n",
      "Scarpping rank 46 of 250\n",
      "Scarpping rank 47 of 250\n",
      "Scarpping rank 48 of 250\n",
      "Scarpping rank 49 of 250\n",
      "Scarpping rank 50 of 250\n",
      "Scarpping rank 51 of 250\n",
      "Scarpping rank 52 of 250\n",
      "Scarpping rank 53 of 250\n",
      "Scarpping rank 54 of 250\n",
      "Scarpping rank 55 of 250\n",
      "Scarpping rank 56 of 250\n",
      "Scarpping rank 57 of 250\n",
      "Scarpping rank 58 of 250\n",
      "Scarpping rank 59 of 250\n",
      "Scarpping rank 60 of 250\n",
      "Scarpping rank 61 of 250\n",
      "Scarpping rank 62 of 250\n",
      "Scarpping rank 63 of 250\n",
      "Scarpping rank 64 of 250\n",
      "Scarpping rank 65 of 250\n",
      "Scarpping rank 66 of 250\n",
      "Scarpping rank 67 of 250\n",
      "Scarpping rank 68 of 250\n",
      "Scarpping rank 69 of 250\n",
      "Scarpping rank 70 of 250\n",
      "Scarpping rank 71 of 250\n",
      "Scarpping rank 72 of 250\n",
      "Scarpping rank 73 of 250\n",
      "Scarpping rank 74 of 250\n",
      "Scarpping rank 75 of 250\n",
      "Scarpping rank 76 of 250\n",
      "Scarpping rank 77 of 250\n",
      "Scarpping rank 78 of 250\n",
      "Scarpping rank 79 of 250\n",
      "Scarpping rank 80 of 250\n",
      "Scarpping rank 81 of 250\n",
      "Scarpping rank 82 of 250\n",
      "Scarpping rank 83 of 250\n",
      "Scarpping rank 84 of 250\n",
      "Scarpping rank 85 of 250\n",
      "Scarpping rank 86 of 250\n",
      "Scarpping rank 87 of 250\n",
      "Scarpping rank 88 of 250\n",
      "Scarpping rank 89 of 250\n",
      "Scarpping rank 90 of 250\n",
      "Scarpping rank 91 of 250\n",
      "Scarpping rank 92 of 250\n",
      "Scarpping rank 93 of 250\n",
      "Scarpping rank 94 of 250\n",
      "Scarpping rank 95 of 250\n",
      "Scarpping rank 96 of 250\n",
      "Scarpping rank 97 of 250\n",
      "Scarpping rank 98 of 250\n",
      "Scarpping rank 99 of 250\n",
      "Scarpping rank 100 of 250\n",
      "Scarpping rank 101 of 250\n",
      "Scarpping rank 102 of 250\n",
      "Scarpping rank 103 of 250\n",
      "Scarpping rank 104 of 250\n",
      "Scarpping rank 105 of 250\n",
      "Scarpping rank 106 of 250\n",
      "Scarpping rank 107 of 250\n",
      "Scarpping rank 108 of 250\n",
      "Scarpping rank 109 of 250\n",
      "Scarpping rank 110 of 250\n",
      "Scarpping rank 111 of 250\n",
      "Scarpping rank 112 of 250\n",
      "Scarpping rank 113 of 250\n",
      "Scarpping rank 114 of 250\n",
      "Scarpping rank 115 of 250\n",
      "Scarpping rank 116 of 250\n",
      "Scarpping rank 117 of 250\n",
      "Scarpping rank 118 of 250\n",
      "Scarpping rank 119 of 250\n",
      "Scarpping rank 120 of 250\n",
      "Scarpping rank 121 of 250\n",
      "Scarpping rank 122 of 250\n",
      "Scarpping rank 123 of 250\n",
      "Scarpping rank 124 of 250\n",
      "Scarpping rank 125 of 250\n",
      "Scarpping rank 126 of 250\n",
      "Scarpping rank 127 of 250\n",
      "Scarpping rank 128 of 250\n",
      "Scarpping rank 129 of 250\n",
      "Scarpping rank 130 of 250\n",
      "Scarpping rank 131 of 250\n",
      "Scarpping rank 132 of 250\n",
      "Scarpping rank 133 of 250\n",
      "Scarpping rank 134 of 250\n",
      "Scarpping rank 135 of 250\n",
      "Scarpping rank 136 of 250\n",
      "Scarpping rank 137 of 250\n",
      "Scarpping rank 138 of 250\n",
      "Scarpping rank 139 of 250\n",
      "Scarpping rank 140 of 250\n",
      "Scarpping rank 141 of 250\n",
      "Scarpping rank 142 of 250\n",
      "Scarpping rank 143 of 250\n",
      "Scarpping rank 144 of 250\n",
      "Scarpping rank 145 of 250\n",
      "Scarpping rank 146 of 250\n",
      "Scarpping rank 147 of 250\n",
      "Scarpping rank 148 of 250\n",
      "Scarpping rank 149 of 250\n",
      "Scarpping rank 150 of 250\n",
      "Scarpping rank 151 of 250\n",
      "Scarpping rank 152 of 250\n",
      "Scarpping rank 153 of 250\n",
      "Scarpping rank 154 of 250\n",
      "Scarpping rank 155 of 250\n",
      "Scarpping rank 156 of 250\n",
      "Scarpping rank 157 of 250\n",
      "Scarpping rank 158 of 250\n",
      "Scarpping rank 159 of 250\n",
      "Scarpping rank 160 of 250\n",
      "Scarpping rank 161 of 250\n",
      "Scarpping rank 162 of 250\n",
      "Scarpping rank 163 of 250\n",
      "Scarpping rank 164 of 250\n",
      "Scarpping rank 165 of 250\n",
      "Scarpping rank 166 of 250\n",
      "Scarpping rank 167 of 250\n",
      "Scarpping rank 168 of 250\n",
      "Scarpping rank 169 of 250\n",
      "Scarpping rank 170 of 250\n",
      "Scarpping rank 171 of 250\n",
      "Scarpping rank 172 of 250\n",
      "Scarpping rank 173 of 250\n",
      "Scarpping rank 174 of 250\n",
      "Scarpping rank 175 of 250\n",
      "Scarpping rank 176 of 250\n",
      "Scarpping rank 177 of 250\n",
      "Scarpping rank 178 of 250\n",
      "Scarpping rank 179 of 250\n",
      "Scarpping rank 180 of 250\n",
      "Scarpping rank 181 of 250\n",
      "Scarpping rank 182 of 250\n",
      "Scarpping rank 183 of 250\n",
      "Scarpping rank 184 of 250\n",
      "Scarpping rank 185 of 250\n",
      "Scarpping rank 186 of 250\n",
      "Scarpping rank 187 of 250\n",
      "Scarpping rank 188 of 250\n",
      "Scarpping rank 189 of 250\n",
      "Scarpping rank 190 of 250\n",
      "Scarpping rank 191 of 250\n",
      "Scarpping rank 192 of 250\n",
      "Scarpping rank 193 of 250\n",
      "Scarpping rank 194 of 250\n",
      "Scarpping rank 195 of 250\n",
      "Scarpping rank 196 of 250\n",
      "Scarpping rank 197 of 250\n",
      "Scarpping rank 198 of 250\n",
      "Scarpping rank 199 of 250\n",
      "Scarpping rank 200 of 250\n",
      "Scarpping rank 201 of 250\n",
      "Scarpping rank 202 of 250\n",
      "Scarpping rank 203 of 250\n",
      "Scarpping rank 204 of 250\n",
      "Scarpping rank 205 of 250\n",
      "Scarpping rank 206 of 250\n",
      "Scarpping rank 207 of 250\n",
      "Scarpping rank 208 of 250\n",
      "Scarpping rank 209 of 250\n",
      "Scarpping rank 210 of 250\n",
      "Scarpping rank 211 of 250\n",
      "Scarpping rank 212 of 250\n",
      "Scarpping rank 213 of 250\n",
      "Scarpping rank 214 of 250\n",
      "Scarpping rank 215 of 250\n",
      "Scarpping rank 216 of 250\n",
      "Scarpping rank 217 of 250\n",
      "Scarpping rank 218 of 250\n",
      "Scarpping rank 219 of 250\n",
      "Scarpping rank 220 of 250\n",
      "Scarpping rank 221 of 250\n",
      "Scarpping rank 222 of 250\n",
      "Scarpping rank 223 of 250\n",
      "Scarpping rank 224 of 250\n",
      "Scarpping rank 225 of 250\n",
      "Scarpping rank 226 of 250\n",
      "Scarpping rank 227 of 250\n",
      "Scarpping rank 228 of 250\n",
      "Scarpping rank 229 of 250\n",
      "Scarpping rank 230 of 250\n",
      "Scarpping rank 231 of 250\n",
      "Scarpping rank 232 of 250\n",
      "Scarpping rank 233 of 250\n",
      "Scarpping rank 234 of 250\n",
      "Scarpping rank 235 of 250\n",
      "Scarpping rank 236 of 250\n",
      "Scarpping rank 237 of 250\n",
      "Scarpping rank 238 of 250\n",
      "Scarpping rank 239 of 250\n",
      "Scarpping rank 240 of 250\n",
      "Scarpping rank 241 of 250\n",
      "Scarpping rank 242 of 250\n",
      "Scarpping rank 243 of 250\n",
      "Scarpping rank 244 of 250\n",
      "Scarpping rank 245 of 250\n",
      "Scarpping rank 246 of 250\n",
      "Scarpping rank 247 of 250\n",
      "Scarpping rank 248 of 250\n",
      "Scarpping rank 249 of 250\n",
      "Scarpping rank 250 of 250\n"
     ]
    }
   ],
   "source": [
    "\n",
    "for record in records:\n",
    "    rank = record.get('rank')\n",
    "    print(f'Scarpping rank {rank} of 250')\n",
    "    link = record.get('link')\n",
    "    response = requests.get(link,headers=header).text\n",
    "    soup = BeautifulSoup(response,'html.parser')\n",
    "    record['title'] = soup.find('h1').find('span').get_text()\n",
    "    record['year'] = soup.find('h1').find(class_='year').get_text()[1:5]\n",
    "    record['director'] = soup.find(id='info').find(class_='attrs').find('a').get_text()\n",
    "    record['length'] = soup.find(id='info').find(property='v:runtime').get_text()[:-2]\n",
    "    \n",
    "    attrs = soup.find(id='info').find_all(class_='pl')\n",
    "    for attr in attrs:\n",
    "        if attr.get_text().startswith('制片国家'):\n",
    "            record['country_region']=attr.nextSibling.strip()\n",
    "        elif attr.get_text().startswith('语言'):\n",
    "            record['language']=attr.nextSibling.strip()\n",
    "    \n",
    "    record['avg_rating'] = soup.find(class_='ll rating_num').get_text()\n",
    "    record['num_of_ratings'] = soup.find(class_='rating_people').find('span').get_text()\n",
    "    interests = soup.find(class_='subject-others-interests-ft').find_all('a')\n",
    "    record['people_watched'] = interests[0].get_text()[:-3]\n",
    "    record['people_wants_to_watch'] = interests[1].get_text()[:-3]\n",
    "    record['num_comment'] = soup.find(id='comments-section').find('h2').find('a').get_text().split()[1]\n",
    "    record['num_reviews'] = soup.find(class_='reviews mod movie-content').find('h2').find('a').get_text().split()[1]\n",
    "    #Set scrapping interval in case of ip blocking\n",
    "    sleep(5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （3）存储csv文件到本地"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "with open('douban_top_250.csv','w', newline='', encoding='utf-8-sig') as file:\n",
    "    headers = [key for key in records[0].keys()]\n",
    "    csv_writer = DictWriter(file, fieldnames=headers)\n",
    "    csv_writer.writeheader()\n",
    "    for record in records:\n",
    "        csv_writer.writerow(record)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、数据清洗"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （1）数据清洗，存储到新的cleaned_data.csv中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv('douban_top_250.csv',encoding='utf-8-sig')\n",
    "data['Chinese_title'] = data['title'].apply(lambda title:title.split()[0])\n",
    "data.drop(['title'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （2）电影时长处理，利用列表推导和split()将多余的字符串去掉"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['movie_length'] = [int(i[0]) for i in data['length'].str.split('分')]\n",
    "data.drop(['length'], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （3）#电影国家地区清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['main_country_region'] = data['country_region'].apply(lambda cr:cr.split()[0])\n",
    "data.drop(['country_region'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （4）电影语种清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['main_language'] = data['language'].apply(lambda lan:lan.split()[0])\n",
    "data.drop(['language'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### （5）字符串（str）转整型（int）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['rank'] = [int(i) for i in data['rank']]\n",
    "data['year'] = [int(i) for i in data['year']]\n",
    "data['avg_rating'] = [float(i) for i in data['avg_rating']]\n",
    "data['num_of_ratings'] = [int(i) for i in data['num_of_ratings']]\n",
    "data['people_watched'] = [int(i) for i in data['people_watched']]\n",
    "data['people_wants_to_watch'] = [int(i) for i in data['people_wants_to_watch']]\n",
    "data['num_comment'] = [int(i) for i in data['num_comment']]\n",
    "data.to_csv('cleaned_data.csv',encoding='utf-8-sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rank</th>\n",
       "      <th>link</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "      <th>length</th>\n",
       "      <th>country_region</th>\n",
       "      <th>language</th>\n",
       "      <th>avg_rating</th>\n",
       "      <th>num_of_ratings</th>\n",
       "      <th>people_watched</th>\n",
       "      <th>people_wants_to_watch</th>\n",
       "      <th>num_comment</th>\n",
       "      <th>num_reviews</th>\n",
       "      <th>Chinese_title</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>https://movie.douban.com/subject/1292052/</td>\n",
       "      <td>1994</td>\n",
       "      <td>弗兰克·德拉邦特</td>\n",
       "      <td>142</td>\n",
       "      <td>美国</td>\n",
       "      <td>英语</td>\n",
       "      <td>9.7</td>\n",
       "      <td>2386796</td>\n",
       "      <td>3700128</td>\n",
       "      <td>377039</td>\n",
       "      <td>510274</td>\n",
       "      <td>11349</td>\n",
       "      <td>肖申克的救赎</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>https://movie.douban.com/subject/1291546/</td>\n",
       "      <td>1993</td>\n",
       "      <td>陈凯歌</td>\n",
       "      <td>171</td>\n",
       "      <td>中国大陆 / 中国香港</td>\n",
       "      <td>汉语普通话</td>\n",
       "      <td>9.6</td>\n",
       "      <td>1777429</td>\n",
       "      <td>2893239</td>\n",
       "      <td>361390</td>\n",
       "      <td>413004</td>\n",
       "      <td>8786</td>\n",
       "      <td>霸王别姬</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>https://movie.douban.com/subject/1292720/</td>\n",
       "      <td>1994</td>\n",
       "      <td>罗伯特·泽米吉斯</td>\n",
       "      <td>142</td>\n",
       "      <td>美国</td>\n",
       "      <td>英语</td>\n",
       "      <td>9.5</td>\n",
       "      <td>1797909</td>\n",
       "      <td>3114598</td>\n",
       "      <td>297835</td>\n",
       "      <td>344481</td>\n",
       "      <td>5912</td>\n",
       "      <td>阿甘正传</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>https://movie.douban.com/subject/1295644/</td>\n",
       "      <td>1994</td>\n",
       "      <td>吕克·贝松</td>\n",
       "      <td>110分钟(剧场</td>\n",
       "      <td>法国 / 美国</td>\n",
       "      <td>英语 / 意大利语 / 法语</td>\n",
       "      <td>9.4</td>\n",
       "      <td>1968554</td>\n",
       "      <td>3453574</td>\n",
       "      <td>340478</td>\n",
       "      <td>387870</td>\n",
       "      <td>5647</td>\n",
       "      <td>这个杀手不太冷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>https://movie.douban.com/subject/1292722/</td>\n",
       "      <td>1997</td>\n",
       "      <td>詹姆斯·卡梅隆</td>\n",
       "      <td>194</td>\n",
       "      <td>美国 / 墨西哥 / 澳大利亚 / 加拿大</td>\n",
       "      <td>英语 / 意大利语 / 德语 / 俄语</td>\n",
       "      <td>9.4</td>\n",
       "      <td>1759250</td>\n",
       "      <td>3134287</td>\n",
       "      <td>201680</td>\n",
       "      <td>340400</td>\n",
       "      <td>4207</td>\n",
       "      <td>泰坦尼克号</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rank                                       link  year  director    length  \\\n",
       "0     1  https://movie.douban.com/subject/1292052/  1994  弗兰克·德拉邦特       142   \n",
       "1     2  https://movie.douban.com/subject/1291546/  1993       陈凯歌       171   \n",
       "2     3  https://movie.douban.com/subject/1292720/  1994  罗伯特·泽米吉斯       142   \n",
       "3     4  https://movie.douban.com/subject/1295644/  1994     吕克·贝松  110分钟(剧场   \n",
       "4     5  https://movie.douban.com/subject/1292722/  1997   詹姆斯·卡梅隆       194   \n",
       "\n",
       "          country_region             language  avg_rating  num_of_ratings  \\\n",
       "0                     美国                   英语         9.7         2386796   \n",
       "1            中国大陆 / 中国香港                汉语普通话         9.6         1777429   \n",
       "2                     美国                   英语         9.5         1797909   \n",
       "3                法国 / 美国       英语 / 意大利语 / 法语         9.4         1968554   \n",
       "4  美国 / 墨西哥 / 澳大利亚 / 加拿大  英语 / 意大利语 / 德语 / 俄语         9.4         1759250   \n",
       "\n",
       "   people_watched  people_wants_to_watch  num_comment  num_reviews  \\\n",
       "0         3700128                 377039       510274        11349   \n",
       "1         2893239                 361390       413004         8786   \n",
       "2         3114598                 297835       344481         5912   \n",
       "3         3453574                 340478       387870         5647   \n",
       "4         3134287                 201680       340400         4207   \n",
       "\n",
       "  Chinese_title  \n",
       "0        肖申克的救赎  \n",
       "1          霸王别姬  \n",
       "2          阿甘正传  \n",
       "3       这个杀手不太冷  \n",
       "4         泰坦尼克号  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">people_wants_to_watch</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>min</th>\n",
       "      <th>mean</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>main_country_region</th>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">中国台湾</th>\n",
       "      <th>1991</th>\n",
       "      <td>294214</td>\n",
       "      <td>294214.000000</td>\n",
       "      <td>294214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1993</th>\n",
       "      <td>195986</td>\n",
       "      <td>195986.000000</td>\n",
       "      <td>195986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1994</th>\n",
       "      <td>270913</td>\n",
       "      <td>270913.000000</td>\n",
       "      <td>270913</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000</th>\n",
       "      <td>356126</td>\n",
       "      <td>356126.000000</td>\n",
       "      <td>356126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007</th>\n",
       "      <td>201602</td>\n",
       "      <td>201602.000000</td>\n",
       "      <td>201602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">韩国</th>\n",
       "      <th>2011</th>\n",
       "      <td>203163</td>\n",
       "      <td>262461.666667</td>\n",
       "      <td>376246</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013</th>\n",
       "      <td>142147</td>\n",
       "      <td>228889.200000</td>\n",
       "      <td>319895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016</th>\n",
       "      <td>163518</td>\n",
       "      <td>163518.000000</td>\n",
       "      <td>163518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019</th>\n",
       "      <td>395774</td>\n",
       "      <td>395774.000000</td>\n",
       "      <td>395774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黎巴嫩</th>\n",
       "      <th>2018</th>\n",
       "      <td>383761</td>\n",
       "      <td>383761.000000</td>\n",
       "      <td>383761</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>154 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         people_wants_to_watch                       \n",
       "                                           min           mean     max\n",
       "main_country_region year                                             \n",
       "中国台湾                1991                294214  294214.000000  294214\n",
       "                    1993                195986  195986.000000  195986\n",
       "                    1994                270913  270913.000000  270913\n",
       "                    2000                356126  356126.000000  356126\n",
       "                    2007                201602  201602.000000  201602\n",
       "...                                        ...            ...     ...\n",
       "韩国                  2011                203163  262461.666667  376246\n",
       "                    2013                142147  228889.200000  319895\n",
       "                    2016                163518  163518.000000  163518\n",
       "                    2019                395774  395774.000000  395774\n",
       "黎巴嫩                 2018                383761  383761.000000  383761\n",
       "\n",
       "[154 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('cleaned_data.csv',encoding='utf-8-sig')\n",
    "df.groupby(['main_country_region','year']).agg({\"people_wants_to_watch\":[\"min\",\"mean\",\"max\"]})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三、数据图表可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1、组合折线图制作（探究豆瓣top250电影数量在时间上的变化趋势）  \n",
    "\n",
    "- 对不同上映年的top电影数量进行统计，以探究电影发展的趋势。  \n",
    "\n",
    "- 同时，对不同年份的所有电影进行一个平均值统计，与数量统计进行对比分析。  \n",
    "\n",
    "- 代码运用了列表推导与及groupby的分并合集等技巧来进行数据重塑。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建行和列的列表结果数据\n",
    "年份列表 = [str(i) for i in sorted(list(df.year.unique()))]\n",
    "平均评分 = df.groupby(by = [\"year\"])\\\n",
    "             .agg ({ \"avg_rating\":\"mean\"}) \\\n",
    "             .sort_values(by = \"year\",ascending = True)\n",
    "平均评分列表 = [round(i,1)for i in list(平均评分.avg_rating)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1931</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1936</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1939</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1950</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      year\n",
       "1931     1\n",
       "1936     1\n",
       "1939     1\n",
       "1940     1\n",
       "1950     1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "年份计数 = pd.value_counts(df.year)\n",
    "df_年份计数 = pd.DataFrame(年份计数)\n",
    "df_年份计数 = df_年份计数.rename(columns={0:'计数'})\n",
    "sort_df_年份计数 = df_年份计数.sort_values(by = \"year\",ascending = True)\n",
    "sort_df_年份计数[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"4b7374f285c946d7b515c419ef9d6fc0\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_4b7374f285c946d7b515c419ef9d6fc0 = echarts.init(\n",
       "                    document.getElementById('4b7374f285c946d7b515c419ef9d6fc0'), 'white', {renderer: 'canvas'});\n",
       "                var option_4b7374f285c946d7b515c419ef9d6fc0 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"top250\\u7684\\u7535\\u5f71\\u8bc4\\u4ef7\\u5e73\\u5747\\u5206\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 0,\n",
       "            \"yAxisIndex\": 0,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"stack\": \"\\u603b\\u91cf\",\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"1931\",\n",
       "                    9.3\n",
       "                ],\n",
       "                [\n",
       "                    \"1936\",\n",
       "                    9.3\n",
       "                ],\n",
       "                [\n",
       "                    \"1939\",\n",
       "                    9.3\n",
       "                ],\n",
       "                [\n",
       "                    \"1940\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"1950\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"1952\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1953\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1954\",\n",
       "                    9.3\n",
       "                ],\n",
       "                [\n",
       "                    \"1957\",\n",
       "                    9.5\n",
       "                ],\n",
       "                [\n",
       "                    \"1960\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"1961\",\n",
       "                    9.4\n",
       "                ],\n",
       "                [\n",
       "                    \"1965\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1966\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"1968\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"1972\",\n",
       "                    9.3\n",
       "                ],\n",
       "                [\n",
       "                    \"1974\",\n",
       "                    9.2\n",
       "                ],\n",
       "                [\n",
       "                    \"1975\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1979\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1982\",\n",
       "                    9.5\n",
       "                ],\n",
       "                [\n",
       "                    \"1983\",\n",
       "                    9.2\n",
       "                ],\n",
       "                [\n",
       "                    \"1984\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1986\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"1987\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1988\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"1989\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"1990\",\n",
       "                    8.7\n",
       "                ],\n",
       "                [\n",
       "                    \"1991\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"1992\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"1993\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"1994\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"1995\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"1996\",\n",
       "                    8.7\n",
       "                ],\n",
       "                [\n",
       "                    \"1997\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1998\",\n",
       "                    9.1\n",
       "                ],\n",
       "                [\n",
       "                    \"1999\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2000\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2001\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2002\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2003\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2004\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2005\",\n",
       "                    8.7\n",
       "                ],\n",
       "                [\n",
       "                    \"2006\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2007\",\n",
       "                    8.7\n",
       "                ],\n",
       "                [\n",
       "                    \"2008\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2009\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2010\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2011\",\n",
       "                    9.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2012\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2013\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2014\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2015\",\n",
       "                    8.8\n",
       "                ],\n",
       "                [\n",
       "                    \"2016\",\n",
       "                    8.7\n",
       "                ],\n",
       "                [\n",
       "                    \"2017\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2018\",\n",
       "                    8.9\n",
       "                ],\n",
       "                [\n",
       "                    \"2019\",\n",
       "                    8.8\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"top250\\u7684\\u7535\\u5f71\\u6570\\u91cf\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"stack\": \"\\u603b\\u91cf\",\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"1931\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1936\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1939\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1940\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1950\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1952\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1953\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1954\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1957\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1960\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1961\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1965\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1966\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1968\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1972\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1974\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1975\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1979\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1982\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"1983\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1984\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1986\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1987\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1988\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1989\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1990\",\n",
       "                    2\n",
       "                ],\n",
       "                [\n",
       "                    \"1991\",\n",
       "                    3\n",
       "                ],\n",
       "                [\n",
       "                    \"1992\",\n",
       "                    3\n",
       "                ],\n",
       "                [\n",
       "                    \"1993\",\n",
       "                    4\n",
       "                ],\n",
       "                [\n",
       "                    \"1994\",\n",
       "                    4\n",
       "                ],\n",
       "                [\n",
       "                    \"1995\",\n",
       "                    4\n",
       "                ],\n",
       "                [\n",
       "                    \"1996\",\n",
       "                    4\n",
       "                ],\n",
       "                [\n",
       "                    \"1997\",\n",
       "                    5\n",
       "                ],\n",
       "                [\n",
       "                    \"1998\",\n",
       "                    5\n",
       "                ],\n",
       "                [\n",
       "                    \"1999\",\n",
       "                    5\n",
       "                ],\n",
       "                [\n",
       "                    \"2000\",\n",
       "                    6\n",
       "                ],\n",
       "                [\n",
       "                    \"2001\",\n",
       "                    6\n",
       "                ],\n",
       "                [\n",
       "                    \"2002\",\n",
       "                    6\n",
       "                ],\n",
       "                [\n",
       "                    \"2003\",\n",
       "                    7\n",
       "                ],\n",
       "                [\n",
       "                    \"2004\",\n",
       "                    7\n",
       "                ],\n",
       "                [\n",
       "                    \"2005\",\n",
       "                    8\n",
       "                ],\n",
       "                [\n",
       "                    \"2006\",\n",
       "                    8\n",
       "                ],\n",
       "                [\n",
       "                    \"2007\",\n",
       "                    8\n",
       "                ],\n",
       "                [\n",
       "                    \"2008\",\n",
       "                    8\n",
       "                ],\n",
       "                [\n",
       "                    \"2009\",\n",
       "                    9\n",
       "                ],\n",
       "                [\n",
       "                    \"2010\",\n",
       "                    9\n",
       "                ],\n",
       "                [\n",
       "                    \"2011\",\n",
       "                    9\n",
       "                ],\n",
       "                [\n",
       "                    \"2012\",\n",
       "                    10\n",
       "                ],\n",
       "                [\n",
       "                    \"2013\",\n",
       "                    10\n",
       "                ],\n",
       "                [\n",
       "                    \"2014\",\n",
       "                    10\n",
       "                ],\n",
       "                [\n",
       "                    \"2015\",\n",
       "                    10\n",
       "                ],\n",
       "                [\n",
       "                    \"2016\",\n",
       "                    11\n",
       "                ],\n",
       "                [\n",
       "                    \"2017\",\n",
       "                    12\n",
       "                ],\n",
       "                [\n",
       "                    \"2018\",\n",
       "                    13\n",
       "                ],\n",
       "                [\n",
       "                    \"2019\",\n",
       "                    13\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"top250\\u7684\\u7535\\u5f71\\u8bc4\\u4ef7\\u5e73\\u5747\\u5206\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"top250\\u7684\\u7535\\u5f71\\u8bc4\\u4ef7\\u5e73\\u5747\\u5206\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"right\": \"20%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        },\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"top250\\u7684\\u7535\\u5f71\\u6570\\u91cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"top250\\u7684\\u7535\\u5f71\\u6570\\u91cf\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"left\": \"20%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"boundaryGap\": false,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"1931\",\n",
       "                \"1936\",\n",
       "                \"1939\",\n",
       "                \"1940\",\n",
       "                \"1950\",\n",
       "                \"1952\",\n",
       "                \"1953\",\n",
       "                \"1954\",\n",
       "                \"1957\",\n",
       "                \"1960\",\n",
       "                \"1961\",\n",
       "                \"1965\",\n",
       "                \"1966\",\n",
       "                \"1968\",\n",
       "                \"1972\",\n",
       "                \"1974\",\n",
       "                \"1975\",\n",
       "                \"1979\",\n",
       "                \"1982\",\n",
       "                \"1983\",\n",
       "                \"1984\",\n",
       "                \"1986\",\n",
       "                \"1987\",\n",
       "                \"1988\",\n",
       "                \"1989\",\n",
       "                \"1990\",\n",
       "                \"1991\",\n",
       "                \"1992\",\n",
       "                \"1993\",\n",
       "                \"1994\",\n",
       "                \"1995\",\n",
       "                \"1996\",\n",
       "                \"1997\",\n",
       "                \"1998\",\n",
       "                \"1999\",\n",
       "                \"2000\",\n",
       "                \"2001\",\n",
       "                \"2002\",\n",
       "                \"2003\",\n",
       "                \"2004\",\n",
       "                \"2005\",\n",
       "                \"2006\",\n",
       "                \"2007\",\n",
       "                \"2008\",\n",
       "                \"2009\",\n",
       "                \"2010\",\n",
       "                \"2011\",\n",
       "                \"2012\",\n",
       "                \"2013\",\n",
       "                \"2014\",\n",
       "                \"2015\",\n",
       "                \"2016\",\n",
       "                \"2017\",\n",
       "                \"2018\",\n",
       "                \"2019\"\n",
       "            ]\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"boundaryGap\": false,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"1931\",\n",
       "                \"1936\",\n",
       "                \"1939\",\n",
       "                \"1940\",\n",
       "                \"1950\",\n",
       "                \"1952\",\n",
       "                \"1953\",\n",
       "                \"1954\",\n",
       "                \"1957\",\n",
       "                \"1960\",\n",
       "                \"1961\",\n",
       "                \"1965\",\n",
       "                \"1966\",\n",
       "                \"1968\",\n",
       "                \"1972\",\n",
       "                \"1974\",\n",
       "                \"1975\",\n",
       "                \"1979\",\n",
       "                \"1982\",\n",
       "                \"1983\",\n",
       "                \"1984\",\n",
       "                \"1986\",\n",
       "                \"1987\",\n",
       "                \"1988\",\n",
       "                \"1989\",\n",
       "                \"1990\",\n",
       "                \"1991\",\n",
       "                \"1992\",\n",
       "                \"1993\",\n",
       "                \"1994\",\n",
       "                \"1995\",\n",
       "                \"1996\",\n",
       "                \"1997\",\n",
       "                \"1998\",\n",
       "                \"1999\",\n",
       "                \"2000\",\n",
       "                \"2001\",\n",
       "                \"2002\",\n",
       "                \"2003\",\n",
       "                \"2004\",\n",
       "                \"2005\",\n",
       "                \"2006\",\n",
       "                \"2007\",\n",
       "                \"2008\",\n",
       "                \"2009\",\n",
       "                \"2010\",\n",
       "                \"2011\",\n",
       "                \"2012\",\n",
       "                \"2013\",\n",
       "                \"2014\",\n",
       "                \"2015\",\n",
       "                \"2016\",\n",
       "                \"2017\",\n",
       "                \"2018\",\n",
       "                \"2019\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": false,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": false,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bc4\\u4ef7\\u5e73\\u5747\\u5206\\u7edf\\u8ba1\",\n",
       "            \"left\": \"85%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        },\n",
       "        {\n",
       "            \"text\": \"\\u4e0a\\u6620\\u5e74\\u4ee3\\u7edf\\u8ba1\",\n",
       "            \"right\": \"85%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"grid\": [\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"left\": \"55%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        },\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"right\": \"55%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_4b7374f285c946d7b515c419ef9d6fc0.setOption(option_4b7374f285c946d7b515c419ef9d6fc0);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179e79cd0>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Line\n",
    "import pyecharts\n",
    "\n",
    "x_data = 年份列表\n",
    "y_data = 平均评分列表\n",
    "\n",
    "c=(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=x_data)\n",
    "    .add_yaxis(\n",
    "        series_name=\"top250的电影评价平均分\",\n",
    "        stack=\"总量\",\n",
    "        y_axis=y_data,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "\n",
    "\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"评价平均分统计\", pos_left=\"85%\"),\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"axis\"),\n",
    "        legend_opts=opts.LegendOpts(pos_right=\"20%\"),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            type_=\"value\",\n",
    "            axistick_opts=opts.AxisTickOpts(is_show=True),\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True),\n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(type_=\"category\", boundary_gap=False),\n",
    "    )\n",
    ")\n",
    "\n",
    "b=(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=x_data)\n",
    "    .add_yaxis(\n",
    "        series_name=\"top250的电影数量\",\n",
    "        stack=\"总量\",\n",
    "        y_axis=list(sort_df_年份计数.year),\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )    \n",
    "\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"上映年代统计\", pos_right=\"85%\"),\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"axis\"),\n",
    "        legend_opts=opts.LegendOpts(pos_left=\"20%\"),\n",
    "\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            type_=\"value\",\n",
    "            axistick_opts=opts.AxisTickOpts(is_show=True),\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True),\n",
    "            \n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(type_=\"category\", boundary_gap=False),\n",
    "    )\n",
    ")\n",
    "\n",
    "(\n",
    "    Grid()\n",
    "    .add(c, grid_opts=opts.GridOpts(pos_left=\"55%\"))\n",
    "    .add(b, grid_opts=opts.GridOpts(pos_right=\"55%\"))\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  2、饼状图与及条形图制作（展示豆瓣top250中导演作品的情况）¶\n",
    "- 利用pyecharts的饼状图来探究top电影中，出现次数最多的前17位导演的一个占比情况。\n",
    "- 利用pyecharts的滑块条形图来统计分析综合平均评价分最高的前20为导演。\n",
    "- 代码运用了列表推导与及groupby的分并合集等技巧来进行数据重塑。  \n",
    "总结：二者对比发现，数量多的同导演电影，其导演的平均评分并不一定都很高。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>avg_rating</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>陈凯歌</th>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>比利·怀德</th>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>罗伯托·贝尼尼</th>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>罗伯特·泽米吉斯</th>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>谢添</th>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>保罗·杰诺维塞</th>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>卡比尔·汗</th>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新海诚</th>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>普特鹏·普罗萨卡·那·萨克那卡林</th>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>周申</th>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>175 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  avg_rating\n",
       "director                    \n",
       "陈凯歌                      9.6\n",
       "比利·怀德                    9.6\n",
       "罗伯托·贝尼尼                  9.6\n",
       "罗伯特·泽米吉斯                 9.5\n",
       "谢添                       9.5\n",
       "...                      ...\n",
       "保罗·杰诺维塞                  8.5\n",
       "卡比尔·汗                    8.4\n",
       "新海诚                      8.4\n",
       "普特鹏·普罗萨卡·那·萨克那卡林         8.4\n",
       "周申                       8.3\n",
       "\n",
       "[175 rows x 1 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>宫崎骏</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>克里斯托弗·诺兰</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>史蒂文·斯皮尔伯格</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王家卫</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>李安</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           计数\n",
       "宫崎骏         8\n",
       "克里斯托弗·诺兰    7\n",
       "史蒂文·斯皮尔伯格   6\n",
       "王家卫         5\n",
       "李安          5"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df.director.unique()\n",
    "导演平均评分 = df.groupby(by = [\"director\"])\\\n",
    "             .agg ({ \"avg_rating\":\"mean\"}) \\\n",
    "             .sort_values(by = \"avg_rating\",ascending = False)\n",
    "display(导演平均评分)\n",
    "导演列表 = list(df.director)\n",
    "导演计数 = pd.value_counts(导演列表)\n",
    "df_导演计数 = pd.DataFrame(导演计数)\n",
    "df_导演计数 = df_导演计数.rename(columns={0:'计数'})\n",
    "df_导演计数.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['宫崎骏',\n",
       " '克里斯托弗·诺兰',\n",
       " '史蒂文·斯皮尔伯格',\n",
       " '王家卫',\n",
       " '李安',\n",
       " '大卫·芬奇',\n",
       " '是枝裕和',\n",
       " '刘镇伟',\n",
       " '昆汀·塔伦蒂诺',\n",
       " '彼得·杰克逊',\n",
       " '詹姆斯·卡梅隆',\n",
       " '彼特·道格特',\n",
       " '姜文',\n",
       " '今敏',\n",
       " '弗朗西斯·福特·科波拉',\n",
       " '理查德·林克莱特',\n",
       " '朱塞佩·托纳多雷']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[8, 7, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(list(df_导演计数.index)[:17])\n",
    "display(list(df_导演计数.计数)[:17])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"45fedee28a7043e4bf43faf5cb51fe9e\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_45fedee28a7043e4bf43faf5cb51fe9e = echarts.init(\n",
       "                    document.getElementById('45fedee28a7043e4bf43faf5cb51fe9e'), 'white', {renderer: 'canvas'});\n",
       "                var option_45fedee28a7043e4bf43faf5cb51fe9e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5bab\\u5d0e\\u9a8f\",\n",
       "                    \"value\": 8\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u514b\\u91cc\\u65af\\u6258\\u5f17\\u00b7\\u8bfa\\u5170\",\n",
       "                    \"value\": 7\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53f2\\u8482\\u6587\\u00b7\\u65af\\u76ae\\u5c14\\u4f2f\\u683c\",\n",
       "                    \"value\": 6\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u738b\\u5bb6\\u536b\",\n",
       "                    \"value\": 5\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u674e\\u5b89\",\n",
       "                    \"value\": 5\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5927\\u536b\\u00b7\\u82ac\\u5947\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u662f\\u679d\\u88d5\\u548c\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5218\\u9547\\u4f1f\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6606\\u6c40\\u00b7\\u5854\\u4f26\\u8482\\u8bfa\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5f7c\\u5f97\\u00b7\\u6770\\u514b\\u900a\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8a79\\u59c6\\u65af\\u00b7\\u5361\\u6885\\u9686\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5f7c\\u7279\\u00b7\\u9053\\u683c\\u7279\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u59dc\\u6587\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4eca\\u654f\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5f17\\u6717\\u897f\\u65af\\u00b7\\u798f\\u7279\\u00b7\\u79d1\\u6ce2\\u62c9\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7406\\u67e5\\u5fb7\\u00b7\\u6797\\u514b\\u83b1\\u7279\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6731\\u585e\\u4f69\\u00b7\\u6258\\u7eb3\\u591a\\u96f7\",\n",
       "                    \"value\": 3\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"40%\",\n",
       "                \"75%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {c}\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5bab\\u5d0e\\u9a8f\",\n",
       "                \"\\u514b\\u91cc\\u65af\\u6258\\u5f17\\u00b7\\u8bfa\\u5170\",\n",
       "                \"\\u53f2\\u8482\\u6587\\u00b7\\u65af\\u76ae\\u5c14\\u4f2f\\u683c\",\n",
       "                \"\\u738b\\u5bb6\\u536b\",\n",
       "                \"\\u674e\\u5b89\",\n",
       "                \"\\u5927\\u536b\\u00b7\\u82ac\\u5947\",\n",
       "                \"\\u662f\\u679d\\u88d5\\u548c\",\n",
       "                \"\\u5218\\u9547\\u4f1f\",\n",
       "                \"\\u6606\\u6c40\\u00b7\\u5854\\u4f26\\u8482\\u8bfa\",\n",
       "                \"\\u5f7c\\u5f97\\u00b7\\u6770\\u514b\\u900a\",\n",
       "                \"\\u8a79\\u59c6\\u65af\\u00b7\\u5361\\u6885\\u9686\",\n",
       "                \"\\u5f7c\\u7279\\u00b7\\u9053\\u683c\\u7279\",\n",
       "                \"\\u59dc\\u6587\",\n",
       "                \"\\u4eca\\u654f\",\n",
       "                \"\\u5f17\\u6717\\u897f\\u65af\\u00b7\\u798f\\u7279\\u00b7\\u79d1\\u6ce2\\u62c9\",\n",
       "                \"\\u7406\\u67e5\\u5fb7\\u00b7\\u6797\\u514b\\u83b1\\u7279\",\n",
       "                \"\\u6731\\u585e\\u4f69\\u00b7\\u6258\\u7eb3\\u591a\\u96f7\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Top\\u7535\\u5f71\\u5bfc\\u6f14\\u4f5c\\u54c1\\u6570\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_45fedee28a7043e4bf43faf5cb51fe9e.setOption(option_45fedee28a7043e4bf43faf5cb51fe9e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179e912e0>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Pie,Bar\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\n",
    "        \"\",\n",
    "        [list(z) for z in zip(list(df_导演计数.index)[:17], list(df_导演计数.计数)[:17])],\n",
    "        radius=[\"40%\", \"75%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"Top电影导演作品数\"),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"),\n",
    "    )\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}\"))\n",
    ")\n",
    "\n",
    "\n",
    "c.render_notebook()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['陈凯歌',\n",
       " '比利·怀德',\n",
       " '罗伯托·贝尼尼',\n",
       " '罗伯特·泽米吉斯',\n",
       " '谢添',\n",
       " '伏原健之',\n",
       " '吕克·贝松',\n",
       " '西德尼·吕美特',\n",
       " '万籁鸣',\n",
       " '拉斯·霍尔斯道姆',\n",
       " '克里斯托夫·巴拉蒂',\n",
       " '查理·卓别林',\n",
       " '奥利维埃·纳卡什',\n",
       " '弗兰克·德拉邦特',\n",
       " '张艺谋',\n",
       " '安德鲁·斯坦顿',\n",
       " '李濬益']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[9.6,\n",
       " 9.6,\n",
       " 9.6,\n",
       " 9.5,\n",
       " 9.5,\n",
       " 9.5,\n",
       " 9.4,\n",
       " 9.4,\n",
       " 9.4,\n",
       " 9.4,\n",
       " 9.3,\n",
       " 9.3,\n",
       " 9.3,\n",
       " 9.3,\n",
       " 9.3,\n",
       " 9.3,\n",
       " 9.3]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(list(导演平均评分.index)[:17])\n",
    "display(list(导演平均评分.avg_rating)[:17])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"0e01b6fc70d34e0384932b02fea9fe36\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_0e01b6fc70d34e0384932b02fea9fe36 = echarts.init(\n",
       "                    document.getElementById('0e01b6fc70d34e0384932b02fea9fe36'), 'white', {renderer: 'canvas'});\n",
       "                var option_0e01b6fc70d34e0384932b02fea9fe36 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u5bfc\\u6f14\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                9.6,\n",
       "                9.6,\n",
       "                9.6,\n",
       "                9.5,\n",
       "                9.5,\n",
       "                9.5,\n",
       "                9.4,\n",
       "                9.4,\n",
       "                9.4,\n",
       "                9.4,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.3,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.2,\n",
       "                9.166666666666666,\n",
       "                9.166666666666666,\n",
       "                9.133333333333333,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.1,\n",
       "                9.05,\n",
       "                9.014285714285714,\n",
       "                9.000000000000002,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                8.987499999999999,\n",
       "                8.966666666666669,\n",
       "                8.966666666666667,\n",
       "                8.966666666666667,\n",
       "                8.95,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.9,\n",
       "                8.899999999999999,\n",
       "                8.899999999999999,\n",
       "                8.879999999999999,\n",
       "                8.850000000000001,\n",
       "                8.85,\n",
       "                8.85,\n",
       "                8.833333333333334,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.8,\n",
       "                8.799999999999999,\n",
       "                8.766666666666667,\n",
       "                8.75,\n",
       "                8.75,\n",
       "                8.75,\n",
       "                8.75,\n",
       "                8.75,\n",
       "                8.75,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.7,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.6,\n",
       "                8.55,\n",
       "                8.55,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.5,\n",
       "                8.4,\n",
       "                8.4,\n",
       "                8.4,\n",
       "                8.3\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5bfc\\u6f14\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5bfc\\u6f14\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"\\u9648\\u51ef\\u6b4c\",\n",
       "                \"\\u6bd4\\u5229\\u00b7\\u6000\\u5fb7\",\n",
       "                \"\\u7f57\\u4f2f\\u6258\\u00b7\\u8d1d\\u5c3c\\u5c3c\",\n",
       "                \"\\u7f57\\u4f2f\\u7279\\u00b7\\u6cfd\\u7c73\\u5409\\u65af\",\n",
       "                \"\\u8c22\\u6dfb\",\n",
       "                \"\\u4f0f\\u539f\\u5065\\u4e4b\",\n",
       "                \"\\u5415\\u514b\\u00b7\\u8d1d\\u677e\",\n",
       "                \"\\u897f\\u5fb7\\u5c3c\\u00b7\\u5415\\u7f8e\\u7279\",\n",
       "                \"\\u4e07\\u7c41\\u9e23\",\n",
       "                \"\\u62c9\\u65af\\u00b7\\u970d\\u5c14\\u65af\\u9053\\u59c6\",\n",
       "                \"\\u514b\\u91cc\\u65af\\u6258\\u592b\\u00b7\\u5df4\\u62c9\\u8482\",\n",
       "                \"\\u67e5\\u7406\\u00b7\\u5353\\u522b\\u6797\",\n",
       "                \"\\u5965\\u5229\\u7ef4\\u57c3\\u00b7\\u7eb3\\u5361\\u4ec0\",\n",
       "                \"\\u5f17\\u5170\\u514b\\u00b7\\u5fb7\\u62c9\\u90a6\\u7279\",\n",
       "                \"\\u5f20\\u827a\\u8c0b\",\n",
       "                \"\\u5b89\\u5fb7\\u9c81\\u00b7\\u65af\\u5766\\u987f\",\n",
       "                \"\\u674e\\u6fec\\u76ca\",\n",
       "                \"\\u7ef4\\u514b\\u591a\\u00b7\\u5f17\\u83b1\\u660e\",\n",
       "                \"\\u9ec4\\u4e1c\\u8d6b\",\n",
       "                \"\\u8d1d\\u7eb3\\u5c14\\u591a\\u00b7\\u8d1d\\u6258\\u9c81\\u5947\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5bfc\\u6f14\\u7684\\u7535\\u5f71\\u5e73\\u5747\\u5206\\u6392\\u884c\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 20,\n",
       "        \"end\": 80,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_0e01b6fc70d34e0384932b02fea9fe36.setOption(option_0e01b6fc70d34e0384932b02fea9fe36);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179ebf790>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis(list(导演平均评分.index)[:20])\n",
    "    .add_yaxis(\"导演\",list(导演平均评分.avg_rating))\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"导演的电影平均分排行\"),\n",
    "        datazoom_opts=opts.DataZoomOpts(),\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3、词云与地图制作（展示国家和语种在豆瓣top250的分布情况）¶\n",
    "- 利用词云图表来展示top电影中出现最多的国家与及语种。\n",
    "- 同时还运用了世界地图来地图可视化top电影中出现最多的国家。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>美国</th>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日本</th>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中国香港</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英国</th>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中国大陆</th>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       计数\n",
       "美国    110\n",
       "日本     34\n",
       "中国香港   20\n",
       "英国     17\n",
       "中国大陆   16"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "国家列表 = list(df.main_country_region)\n",
    "国家计数 = pd.value_counts(国家列表)\n",
    "df_国家计数 = pd.DataFrame(国家计数)\n",
    "df_国家计数 = df_国家计数.rename(columns={0:'计数'})\n",
    "df_国家计数.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['美国',\n",
       " '日本',\n",
       " '中国香港',\n",
       " '英国',\n",
       " '中国大陆',\n",
       " '韩国',\n",
       " '法国',\n",
       " '中国台湾',\n",
       " '意大利',\n",
       " '德国',\n",
       " '印度',\n",
       " '澳大利亚',\n",
       " '泰国',\n",
       " '爱尔兰',\n",
       " '伊朗',\n",
       " '西班牙',\n",
       " '丹麦',\n",
       " '巴西',\n",
       " '瑞典',\n",
       " '阿根廷',\n",
       " '新西兰',\n",
       " '黎巴嫩']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[110, 34, 20, 17, 16, 11, 8, 6, 6, 5, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(list(df_国家计数.index))\n",
    "display(list(df_国家计数.计数))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "国家列表=list(df_国家计数.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'echarts-wordcloud':'https://assets.pyecharts.org/assets/echarts-wordcloud.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"8acd483d370c463e8d0796a8cbbda970\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'echarts-wordcloud'], function(echarts) {\n",
       "                var chart_8acd483d370c463e8d0796a8cbbda970 = echarts.init(\n",
       "                    document.getElementById('8acd483d370c463e8d0796a8cbbda970'), 'white', {renderer: 'canvas'});\n",
       "                var option_8acd483d370c463e8d0796a8cbbda970 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"shape\": \"diamond\",\n",
       "            \"rotationRange\": [\n",
       "                0,\n",
       "                0\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                30,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u7f8e\\u56fd\",\n",
       "                    \"value\": 110,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(68,43,46)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65e5\\u672c\",\n",
       "                    \"value\": 34,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(38,120,7)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e2d\\u56fd\\u9999\\u6e2f\",\n",
       "                    \"value\": 20,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(54,86,81)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u82f1\\u56fd\",\n",
       "                    \"value\": 17,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(46,91,4)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e2d\\u56fd\\u5927\\u9646\",\n",
       "                    \"value\": 16,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(125,17,115)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u97e9\\u56fd\",\n",
       "                    \"value\": 11,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(120,20,144)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cd5\\u56fd\",\n",
       "                    \"value\": 8,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(27,92,98)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e2d\\u56fd\\u53f0\\u6e7e\",\n",
       "                    \"value\": 6,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(0,7,18)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u610f\\u5927\\u5229\",\n",
       "                    \"value\": 6,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(103,19,34)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5fb7\\u56fd\",\n",
       "                    \"value\": 5,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(19,18,84)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5370\\u5ea6\",\n",
       "                    \"value\": 4,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(109,92,154)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6fb3\\u5927\\u5229\\u4e9a\",\n",
       "                    \"value\": 3,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(29,96,43)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cf0\\u56fd\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(115,27,88)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7231\\u5c14\\u5170\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(66,53,10)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4f0a\\u6717\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(38,92,20)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u73ed\\u7259\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(51,80,121)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e39\\u9ea6\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(109,19,21)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5df4\\u897f\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(0,36,1)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u745e\\u5178\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(113,103,84)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u963f\\u6839\\u5ef7\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(77,51,48)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u897f\\u5170\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(30,34,143)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ece\\u5df4\\u5ae9\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(68,24,89)\"\n",
       "                        }\n",
       "                    }\n",
       "                }\n",
       "            ],\n",
       "            \"drawOutOfBound\": false,\n",
       "            \"textStyle\": {\n",
       "                \"emphasis\": {}\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u56fd\\u5bb6\\u70ed\\u70b9\\u5206\\u6790\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_8acd483d370c463e8d0796a8cbbda970.setOption(option_8acd483d370c463e8d0796a8cbbda970);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179e7f610>"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "\n",
    "\n",
    "words = [list(z) for z in zip(list(df_国家计数.index), list(df_国家计数.计数))]\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(\"\", words, word_size_range=[30, 100], shape=SymbolType.DIAMOND)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"国家热点分析\"))\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'world':'https://assets.pyecharts.org/assets/maps/world'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"98deaf25d15f48e8a164d4fe7f68a88d\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'world'], function(echarts) {\n",
       "                var chart_98deaf25d15f48e8a164d4fe7f68a88d = echarts.init(\n",
       "                    document.getElementById('98deaf25d15f48e8a164d4fe7f68a88d'), 'white', {renderer: 'canvas'});\n",
       "                var option_98deaf25d15f48e8a164d4fe7f68a88d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u9690\\u85cf\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"world\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u8ba1\\u6570\",\n",
       "                    \"value\": 110\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {},\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u9690\\u85cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u9690\\u85cf\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8c46\\u74e3250\\u7535\\u5f71\\u6570\\u91cf\\u6570\\u636e\\u4e16\\u754c\\u53d1\\u5e03\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 200,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_98deaf25d15f48e8a164d4fe7f68a88d.setOption(option_98deaf25d15f48e8a164d4fe7f68a88d);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179e7f340>"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(\"隐藏\", [list(z) for z in zip(df_国家计数,list(df_国家计数.计数))], \"world\")\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"豆瓣250电影数量数据世界发布\"),\n",
    "        visualmap_opts=opts.VisualMapOpts(max_=200),\n",
    "    )\n",
    "\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日语</th>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>粤语</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>汉语普通话</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>韩语</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        计数\n",
       "英语     139\n",
       "日语      34\n",
       "粤语      20\n",
       "汉语普通话   20\n",
       "韩语      11"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "语种列表 = list(df.main_language)\n",
    "语种计数 = pd.value_counts(语种列表)\n",
    "df_语种计数 = pd.DataFrame(语种计数)\n",
    "df_语种计数 = df_语种计数.rename(columns={0:'计数'})\n",
    "df_语种计数.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['英语',\n",
       " '日语',\n",
       " '粤语',\n",
       " '汉语普通话',\n",
       " '韩语',\n",
       " '法语',\n",
       " '印地语',\n",
       " '意大利语',\n",
       " '德语',\n",
       " '西班牙语',\n",
       " '葡萄牙语',\n",
       " '瑞典语',\n",
       " '北京话',\n",
       " '闽南语',\n",
       " '丹麦语',\n",
       " '波斯语',\n",
       " '泰语',\n",
       " '阿拉伯语',\n",
       " '南非语']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[139, 34, 20, 20, 11, 5, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "语种列表 = list(df_语种计数.index)\n",
    "display(语种列表)\n",
    "display(list(df_语种计数.计数))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'echarts-wordcloud':'https://assets.pyecharts.org/assets/echarts-wordcloud.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"68b31dae280a414f8a6263feb7d5174b\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'echarts-wordcloud'], function(echarts) {\n",
       "                var chart_68b31dae280a414f8a6263feb7d5174b = echarts.init(\n",
       "                    document.getElementById('68b31dae280a414f8a6263feb7d5174b'), 'white', {renderer: 'canvas'});\n",
       "                var option_68b31dae280a414f8a6263feb7d5174b = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"name\": \"\\u8bed\\u79cd\\u70ed\\u70b9\\u5206\\u6790\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                30,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u82f1\\u8bed\",\n",
       "                    \"value\": 139,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(52,129,62)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65e5\\u8bed\",\n",
       "                    \"value\": 34,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(128,7,90)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7ca4\\u8bed\",\n",
       "                    \"value\": 20,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(24,11,85)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c49\\u8bed\\u666e\\u901a\\u8bdd\",\n",
       "                    \"value\": 20,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(77,80,2)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u97e9\\u8bed\",\n",
       "                    \"value\": 11,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(126,48,47)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cd5\\u8bed\",\n",
       "                    \"value\": 5,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(90,75,72)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5370\\u5730\\u8bed\",\n",
       "                    \"value\": 4,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(73,92,37)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u610f\\u5927\\u5229\\u8bed\",\n",
       "                    \"value\": 4,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(65,115,131)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5fb7\\u8bed\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(91,13,109)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u73ed\\u7259\\u8bed\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(134,99,65)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8461\\u8404\\u7259\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(30,129,117)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u745e\\u5178\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(152,57,26)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\\u8bdd\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(118,27,160)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u95fd\\u5357\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(80,51,134)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e39\\u9ea6\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(157,50,113)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6ce2\\u65af\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(107,101,144)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cf0\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(66,26,93)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u963f\\u62c9\\u4f2f\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(33,25,89)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5357\\u975e\\u8bed\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(74,142,67)\"\n",
       "                        }\n",
       "                    }\n",
       "                }\n",
       "            ],\n",
       "            \"drawOutOfBound\": false,\n",
       "            \"textStyle\": {\n",
       "                \"emphasis\": {}\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bed\\u79cd\\u70ed\\u70b9\\u5206\\u6790\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 23\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_68b31dae280a414f8a6263feb7d5174b.setOption(option_68b31dae280a414f8a6263feb7d5174b);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x19179ef0e50>"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "\n",
    "\n",
    "data = [list(z) for z in zip(语种列表, list(df_语种计数.计数))]\n",
    "\n",
    "\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(series_name=\"语种热点分析\", data_pair=data, word_size_range=[30, 100])\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(\n",
    "            title=\"语种热点分析\", title_textstyle_opts=opts.TextStyleOpts(font_size=23)\n",
    "        ),\n",
    "        tooltip_opts=opts.TooltipOpts(is_show=True),\n",
    "    )\n",
    ")\n",
    "c.render_notebook()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
